﻿
$.fn.serializeNoViewState = function () {

    var inputs = this.find(':disabled');
    inputs.prop('disabled', false);
    var serialized = this.find("input,textarea,select,hidden").not("[type=hidden][name^=__]").serialize();
    inputs.prop('disabled', true);
    return serialized;

}

function toIDR(value) {

    var str = value.toString();

    var precision = new String(str.substring(0, str.lastIndexOf('.')));
    var scale = new String(str.substring(str.lastIndexOf('.') + 1));

    precision = precision.split("").reverse();

    var output = "";
    for (var i = 0; i <= precision.length - 1; i++) {
        output = precision[i] + output;
        if ((i + 1) % 3 == 0 && (precision.length - 1) !== i) output = '.' + output;
    }

    return output + ',' + scale;
}

function IDRcurrency(cellvalue, options, rowObject) {

    if (cellvalue == '' || cellvalue == undefined)
        cellvalue = '0.00';

    return toIDR(cellvalue);

}

Number.prototype.formatMoney = function (decPlaces, thouSeparator, decSeparator) {
    var n = this,
    decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces,
    decSeparator = decSeparator == undefined ? "." : decSeparator,
    thouSeparator = thouSeparator == undefined ? "," : thouSeparator,
    sign = n < 0 ? "-" : "",
    i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "",
    j = (j = i.length) > 3 ? j % 3 : 0;
    return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : "");
};

$.fn.extend({
    // Converts with every keystroke the hole text to uppercase
    upperCase: function () {
        $(this).keyup(function (event) {
            var box = event.target;
            var txt = $(this).val();
            var start = box.selectionStart;
            var end = box.selectionEnd;

            $(this).val(txt.toUpperCase());
            box.setSelectionRange(start, end);
        });
        return this;
    }

});

function CallAjax(urlx, parameter) {
    $.ajax({
        type: 'GET',
        url: urlx + parameter,
        contentType: 'application/json',
        dataType: 'json',
        data: '{}',
        success: function (data) {
            if (data.IsSuccess) {
                alert(data.Message);
            }
            else {
                alert(data.Message);
            }
        },
        error: function (response) {
            var r = JSON.parse(response.responseText);
            alert("Error Message: " + r.Message);
        }
    });
}

function CallAjax(urlx, parameter, jsondata) {
    $.ajax({
        type: 'POST',
        url: urlx + parameter,
        contentType: 'application/json',
        dataType: 'json',
        data: jsondata,
        success: function(data) {
            if (data.IsSuccess) {
                alert(data.Message);
            }
            else {
                alert(data.Message);
            }
        },
        error: function (response) {
            var r = JSON.parse(response.responseText);
            alert("Error Message: " + r.Message);
        }
    });
}


